package com.boc.langxiang.presenter.adm;


import com.boc.langxiang.contract.adm.ArtistMessageContract;
import com.boc.langxiang.entity.request.AdmMessageCreateRequest;
import com.boc.langxiang.entity.request.ArtistMessageRequest;
import com.boc.langxiang.entity.response.AdmAboutContent;
import com.boc.langxiang.entity.response.AdmAboutEntity;
import com.boc.langxiang.entity.response.AritstMessageContent;
import com.boc.langxiang.entity.response.AritstMessageEntity;
import com.boc.langxiang.entity.response.BaseResponse;
import com.boc.langxiang.net.ApiService;
import com.boc.langxiang.net.HandleErrorSubscriber;
import com.boc.langxiang.net.NetClient;

import java.util.List;

import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * CreateTime: 2016-06-14上午10:40
 * Author: wjkjinke00@126.com
 * Description:
 */
public class ArtistMessagePresenter implements ArtistMessageContract.Presenter {

    private final ApiService mService;
    private ArtistMessageContract.View mView;

    public ArtistMessagePresenter(ArtistMessageContract.View view) {
        mService = NetClient.getInstance().net().create(ApiService.class);
        mView = view;
    }


    @Override
    public void admMessage(ArtistMessageRequest request) {
        //        mView.showLoading();
        mService.admMessage(request.params())
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .unsubscribeOn(Schedulers.io())
                .subscribe(new HandleErrorSubscriber<BaseResponse<AritstMessageContent>>(mView) {
                    @Override
                    public void onSuccess(BaseResponse<AritstMessageContent> response) {
                        AritstMessageContent content = response.getContent();
                        if (content != null) {
                            List<AritstMessageEntity> res = content.getRes();
                            mView.admMessageSuccess(res);
                        }else{
                            mView.admMessageSuccess(null);
                        }
                    }
                });
    }

    @Override
    public void createMessage(AdmMessageCreateRequest request) {
        mView.showCreateMessageDialog();
        mService.messageCreate(request.params())
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .unsubscribeOn(Schedulers.io())
                .subscribe(new HandleErrorSubscriber<BaseResponse>(mView) {
                    @Override
                    public void onSuccess(BaseResponse response) {
                        mView.createMessageSuccess();
                    }
                });
    }
}
